package com.candy.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 进行字符集过滤的方法
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
//    实际处理业务的方法
    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        chain.doFilter(req,resp);
    }
//过滤器初始化时进行调用
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
//当过滤器销毁时进行调用
    @Override
    public void destroy() {

    }
}
